class EventCenter:
    _instance = None  # 用于存储单例实例

    def __new__(cls, *args, **kwargs):
        # 如果实例不存在，则创建一个新的实例
        if cls._instance is None:
            cls._instance = super(EventCenter, cls).__new__(cls)
            cls._instance._eventchangeListeners = {}
        return cls._instance

    def add_event(self, key, listener):
        if key not in self._eventchangeListeners:
            self._eventchangeListeners[key] = []
        self._eventchangeListeners[key].append(listener)

    def remove_event(self, key, listener):
        if key in self._eventchangeListeners:
            self._eventchangeListeners[key].remove(listener)

    def dispatch_event(self, key, *value):
        if key in self._eventchangeListeners:
            for listener in self._eventchangeListeners[key]:
                listener(*value)

    def clear_event(self):
        self._eventchangeListeners.clear()
    

eventcenter = EventCenter()